class BufferedImage {
	constructor(width, height,
                imageType){
        this.width=width;
        this.height=height;
        this.imageType=imageType;
        this.debug_raster=[];
        let body=document.getElementById("main");
        let canvas=document.createElement("canvas");

        canvas.width = this.width;
        canvas.height = this.height;
        body.appendChild(canvas);
        this.image = canvas.getContext("2d");

    }
    drawInertBody(){
	    let body=document.getElementById("main");
        let canvas=document.createElement("canvas");
        body.appendChild(canvas);
        let cxt2d=canvas.getContext("2d");
         canvas.width = this.width;
         canvas.height = this.height;

         this.drawCanvas(cxt2d);
    }
    drawCanvas(canvas){

        let pixels=this.debug_raster.concat();
        for(let obj in pixels){
            let imgData=canvas.createImageData(1,1);
            for (let i=0;i<imgData.data.length;i+=4)
            {
                imgData.data[i+0]=pixels[obj].pixel[0];
                imgData.data[i+1]=pixels[obj].pixel[1];
                imgData.data[i+2]=pixels[obj].pixel[2];
                imgData.data[i+3]=pixels[obj].pixel[3];
            }
            canvas.putImageData(imgData,pixels[obj].x,pixels[obj].y);
        }
    }
    draw(x,y,pixels){
        this.setPixel(x,y,pixels)
        let imgData=this.image.createImageData(1,1);
        for (let i=0;i<imgData.data.length;i+=4)
        {
            imgData.data[i+0]=pixels[0];
            imgData.data[i+1]=pixels[1];
            imgData.data[i+2]=pixels[2];
            imgData.data[i+3]=pixels[3];
        }
        this.image.putImageData(imgData,x,y);
    }
    toDataURL() {
        return this.image
    }
    getPixel () {
        return  this.debug_raster;
    }
    setPixel (x,y,pixels) {
        this.debug_raster.push({'x': x, 'y': y,'pixel': pixels.concat()});
    }
    get TYPE_INT_ARGB(){

        return 2;
	}

}

 